﻿using System;
using awsomeSyntezator.PipeLine.Filters;

namespace awsomeSyntezator.PipeLine.Oscilators.Effects
{
	class Rain : Oscilator
	{
		private RedNoise red;
		private Filter filter;
		private Pulse pulseGenerator;
		private double scaleLo;
		private double scaleHi;

		public Rain(int strenght) : base(0, 0, strenght)
		{
			red = new RedNoise(Options.noiseDensity,1);
			filter = new HighCutOffFilter(Options.noiseEffectCutOffFrequency, Options.effectResonance);
			pulseGenerator = new Pulse(Options.noiseDensity);
			type = 0;

			scaleLo = 1;
			scaleHi = Options.noiseEffectCutOffFrequency;
		}

		public override double getSample(int n, double sample)
		{
			filter.setParams((float)(((red.getSample(n, sample) + 1.0) / 2.0) * (scaleHi - scaleLo) + scaleLo), Options.effectResonance);
			return filter.getSample(n,pulseGenerator.getSample(n,sample));
		}
	}
}